<template>
	<view style="padding: 0 10px;">
			<uni-forms ref="form" :model="form" :rules="rules">
				<uni-forms-item label="饮水点名称" name="name" required label-width="90px">
					<uni-easyinput v-model="form.name" placeholder="请输入" />
				</uni-forms-item>
				<uni-forms-item label="详情地址" name="address" required label-width="90px">
					<view class="align-center justify-between">
						<uni-easyinput v-model="form.address" placeholder="请选择" />
						<text @click="chooseMap" class="myicon icon-shouhuodizhi" style="font-size: 20px;padding: 6px 8px;"></text>
					</view>
				</uni-forms-item>
				<uni-forms-item label="是否收费" name="is_fee" required label-width="90px">
					<uni-data-checkbox v-model="form.is_fee" :localdata="[{
						text: '否',
						value: 0
					}, {
						text: '是',
						value: 1
					}]" />
				</uni-forms-item>
				<uni-forms-item label="服务配置" name="services" required label-width="90px">
					<uni-data-checkbox v-model="form.services" multiple :localdata="[{icon:'icon-reshui',text:'热水',value:'热水'},{icon:'icon-water',text:'冷水',value:'冷水'},{icon:'icon-zhaocesuo',text:'WC',value:'WC'}]" />
				</uni-forms-item>
				<uni-forms-item label="简介" name="title" label-width="90px">
					<uni-easyinput type="textarea" v-model="form.title" placeholder="请输入简介" />
				</uni-forms-item>
				<uni-forms-item label="开放时间" name="open_time" label-width="90px">
					<uni-easyinput v-model="form.open_time" placeholder="请输入" />
				</uni-forms-item>
				
				<uni-forms-item label="门头照片" name="logo_img" label-width="90px">
					<ImgUpload v-model="form.logo_img" :max="1"/>
				</uni-forms-item>
				
				<view class="btn-primary" @click="submit">提交</view>
			</uni-forms>
	</view>
</template>

<script>
	import ImgUpload from '@/components/ImgUpload.vue'
	
	
	export default {
		components:{
			ImgUpload,
		},
		data() {
			return {
				rules:{
					name: {
						rules: [{
							required: true,
							errorMessage: '名称不能为空',
						}]
					},
					address: {
						rules: [{
							required: true,
							errorMessage: '地址不能为空',
						}]
					},
					is_fee: {
						rules: [{
							required: true,
							errorMessage: '是否收费不能为空',
						}]
					},
					services: {
						rules: [{
							required: true,
							errorMessage: '服务配置不能为空',
						}]
					},
					title: {
						rules: [{
							required: true,
							errorMessage: '简介不能为空',
						}]
					},
					open_time: {
						rules: [{
							required: true,
							errorMessage: '开放时间不能为空',
						}]
					},
					logo_img: {
						rules: [{
							required: true,
							errorMessage: '门头照片不能为空',
						}]
					},
				},
				form:{
					services:[],
					address:'',
				}
			}
		},
		methods: {
			submit(form) {
				console.log('form',this.form)
				this.$refs.form.validate().then(res=>{
					console.log('表单数据信息：', res);
					this.post('crud/save',{table:'mch',...this.form}).then(({code})=>{
						if(code===1){
							this.success('标注成功！');
							this.redirect('/pages/water/mch/mchlist',1200)
						}
					})
					
				}).catch(err =>{
					console.log('表单错误信息：', err);
					this.error(err[0].errorMessage)
				})
			},
			async chooseMap(){
				let location = await this.util.chooseLocation()
				if(location.code==1){
					this.form.longitude = location.longitude
					this.form.latitude = location.latitude
					this.form.province = location.province
					this.form.city = location.city
					this.form.district = location.district
					this.form.address = location.address
				}
				
			}
		}
	}
</script>

<style lang="scss">
.form-item {
	display: flex;
	align-items: center;
}
</style>
